<template>
  <div class="m-investigate">
    <div class="m-header" @click="returnPre">
      <h3 class="titleh3">
        <i class="u-back"></i>满意度调查
      </h3>
    </div>
    <div class="investigatebox">
      <div class="questionbox">
        <div class="questionscroll">
          <p class="desccall">尊敬的患者您好：</p>
          <p class="desctxt">为进一步改善我院就医环境，改善服务态度，提升服务质量，请协助我们进行一次调查，如实回答下面问题，感谢您的支持！(<span style="color:red"> * 该问卷只能填一次 </span>)</p>
          <p class="desctype">住院科室：</p>
          <questionlist @answclick="parentAnswClick"></questionlist>
        </div>
        <div class="m-btns">
          <a class="u-button u-submit" @click="quesubmit">提交</a>
          <router-link to="/" class="u-button">返回</router-link>
        </div>
      </div>
    </div>
    <div v-show="succflag">
      <div class="successtip">已提交！</div>
      <div class="f-mask"></div>
    </div>
    <div v-show="failflag">
      <div class="successtip">请填写完整！</div>
      <div class="f-mask"></div>
    </div>
  </div>
</template>

<script>
import questionlist from './questionlist.vue'
import $ from 'jquery'
import urls from '../../common.js'
import {mapState} from 'vuex'
export default {
  name: 'unopen',
  data () {
    return {
      succflag: false,
      failflag: false
    }
  },
  components: {
    questionlist
  },
  computed: {
    ...mapState({
      bedNo: 'bedNo'
    })
  },
  methods: {
    quesubmit: function () {
      // setTimeout(() => {
      //   this.succflag = false
      //   // this.$router.push({path: '/'})
      // }, 2000)
      // let childqueslist = this.$refs.queslist
      let liAll = $('.choicebox li input:checked')
      let allinput = $('.choicebox li input')
      let all1 = []
      if (liAll.length === $('.choicebox').length) {
        for (let i = 0; i < liAll.length; i++) {
          all1.push(Number($(liAll[i]).val()))
        }
        this.$http
          .post(urls.submit, { bed_no: this.bedNo, answer: '[' + all1 + ']' })
          .then(result => {
            if (result.body.code === '200') {
              for (let i = 0; i < allinput.length; i++) {
                all1.push($(allinput[i]).attr('disabled', 'disabled'))
              }
              $('.u-button').addClass('graybg')
              this.succflag = true
              setTimeout(() => {
                this.succflag = false
              }, 2000)
            }
          })
      } else {
        this.failflag = true
        setTimeout(() => {
          this.failflag = false
        }, 2000)
      }
    },
    parentAnswClick: function (data) {},
    returnPre () {
      this.$router.go(-1)
    }
  }
}
</script>

<style lang="stylus" scoped>
.m-investigate {
  height: 100%;
  background: #f7f8fa;
  text-align: left;

  .m-header {
    height: 0.98rem;
    background: #27ae9e;
    padding: 0 0.3rem;

    .titleh3 {
      font-size: 0.36rem;
      color: #fff;
      text-align: left;
      line-height: 0.98rem;

      .u-back {
        display: inline-block;
        width: 0.18rem;
        height: 0.3rem;
        background-image: url('../../../static/images/satisfaction/back.png');
        background-repeat: no-repeat;
        background-size: 100% 100%;
        margin-right: 0.13rem;
        vertical-align: -0.02rem;
      }
    }
  }

  .investigatebox {
    padding: 0.3rem;
    position: absolute;
    bottom: 0;
    top: 0.98rem;
    left: 0;
    right: 0;

    .questionbox {
      background: #fff;
      border-radius: 0.06rem;
      box-shadow: 0px 0.04rem 0.12rem 0px rgba(127, 135, 143, 0.1);
      padding: 0.3rem;
      height: 100%;
      position: relative;

      .questionscroll {
        position: absolute;
        top: 0;
        left: 0.3rem;
        right: 0.3rem;
        bottom: 1.2rem;
        overflow-y: scroll;

        .desccall {
          text-align: left;
          color: #19191a;
          font-size: 0.24rem;
          padding: 0.24rem 0;
        }

        .desctxt {
          text-align: left;
          color: #292d33;
          font-size: 0.24rem;
          text-indent: 0.48rem;
          line-height: 0.3rem;
        }

        .desctype {
          font-size: 0.26rem;
          color: #19191a;
          padding: 0.3rem 0 0.3rem 0;
        }

        .questionbar {
          margin-bottom: 0.3rem;

          .qustitle {
            font-size: 0.26rem;
            color: #292d33;
            margin-bottom: 0.22rem;
          }

          .choicebox {
            padding: 0 0.2rem 0 0.44rem;

            li {
              font-size: 0.24rem;
              color: #292d33;
              float: left;
              margin-right: 0.65rem;

              .u-radio {
                width: 0.36rem;
                height: 0.36rem;
                -webkit-appearance: none;
                background-image: url('../../../static/images/satisfaction/checkbox.png');
                background-repeat: no-repeat;
                background-size: 100% 100%;
                margin-right: 0.2rem;

                &:checked {
                  background-image: url('../../../static/images/satisfaction/checkboxsel.png');
                }
              }
            }
          }
        }
      }

      .m-btns {
        text-align: right;
        padding: 0 0.3rem;
        position: absolute;
        height: 1.2rem;
        bottom: 0;
        left: 0;
        right: 0;

        .u-button {
          display: inline-block;
          width: 2rem;
          height: 0.8rem;
          line-height: 0.8rem;
          text-align: center;
          font-size: 0.3rem;
          color: #27ae9e;
          background: #fff;
          border: 1px solid #27ae9e;
          border-radius: 0.14rem;
          margin-left: 0.2rem;
        }
      }

      .u-button.u-submit {
        background: #27ae9e;
        color: #fff;
      }
      .u-button.u-submit.graybg {
        background: #ccc;
        border: 1px solid #ccc;
        color: #fff;
      }
    }
  }

  .successtip {
    width: 2.2rem;
    height: 1rem;
    line-height: 1rem;
    color: #fff;
    font-size: 0.3rem;
    text-align: center;
    border-radius: 0.1rem;
    background-color: rgba(0, 0, 0, 0.6);
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -0.5rem 0 0 -1.1rem;
  }

  .f-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    background: rgba(0, 0, 0, 0);
  }
}
</style>
